# build stage
FROM node:20.16 AS build-stage

WORKDIR /app

# 复制所有文件（包括 package.json 和 lock 文件）
COPY . .

# 安装 pnpm 并设置源
RUN npm install -g pnpm && pnpm config set registry https://registry.npmmirror.com/

# 确保安装所有依赖
ENV NODE_ENV=development
RUN pnpm install --no-frozen-lockfile --shamefully-hoist

# 构建
RUN pnpm run build

# production stage
FROM nginx:stable AS production-stage

# 复制构建后的文件到 nginx 目录
COPY --from=build-stage /app/dist /usr/share/nginx/html

# 配置 nginx
COPY nginx/default.conf /etc/nginx/conf.d/default.conf

# 暴露端口
EXPOSE 80

# 启动 nginx
CMD ["nginx", "-g", "daemon off;"]
